﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace YX
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
            InitialGame();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw |
                ControlStyles.AllPaintingInWmPaint, true);

        }

        public void InitialGame()
        {
            SingleClass.GetSingle.AddBaseClase(new BackGround(0, -850, 5));
            SingleClass.GetSingle.AddBaseClase(new MyPlane(400,200,3,Direction.Up));
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            SingleClass.GetSingle.Draw(e.Graphics);
            string score = SingleClass.GetSingle.Score.ToString();
            //绘制玩家的分数
            e.Graphics.DrawString(score, new Font("宋体", 20, FontStyle.Bold), Brushes.Red, new Point(0, 0));
        }

        Random Ran = new Random();

        private void Enemy_Born()
        {
            for (int i = 0; i <= 4; i++)
            {
                SingleClass.GetSingle.AddBaseClase(new EnemyPlane(Ran.Next(80, this.Width)-80, -200, Ran.Next(0, 2)));
            }
            if(Ran.Next(0,100)>80)
            {
                SingleClass.GetSingle.AddBaseClase(new EnemyPlane(Ran.Next(80, this.Width)-80, -200, 2));
            }
        }

        private void BG_Move_Tick(object sender, EventArgs e)
        {
            this.Invalidate();
            int count = SingleClass.GetSingle.EP.Count;
            if(count<=1)
            {
                Enemy_Born();
            }
            SingleClass.GetSingle.PZJC();
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            SingleClass.GetSingle.MP.PlaneMove(e);
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            SingleClass.GetSingle.MP.Fire();
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {

        }

    }
}
